from lxml import etree

import requests

headers = {
    "referer": "https://www.ebay.com/sch/i.html?_nkw=iPhone&_sacat=0&_from=R40&_trksid=m570.l1313",
    "upgrade-insecure-requests": "1",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
}
cookies = {
    "__uzma": "c633cfc5-48ea-43eb-8bab-ce6c94461ee2",
    "__uzmb": "1753971217",
    "__uzme": "2961",
    "ak_bmsc": "20BEC55C465C88E35507BAE7D2742BF3~000000000000000000000000000000~YAAQkvQiF9PRtFqYAQAAj9bUYBz3BjqM/dzHXO0dMeJb3rOnRICJKT6k/BpgdC+3DhLYimh/RUzV4j8C12EQIWDFxGdAaFYmA18K9LMjrcJU8rkv5miR2wdXEPwYmLH7OvwcdnWyYjHGRpCCj82lC6j7OahHxDPWV9wpLPtoQZQFDbsoR1R2Pe/3G3hcAbYJXLDXpmC/7L4cCX97eM7NyepgGMwcKP2SMm4A6bndi6UePuoZBN/D4+1vx59T5TbOrBSRIN6MISwDR5whfhb1TWrUo9UTsFyGhSvwPhH/a4MO9Emnn6mot6x4KXBN9x/xtjDojAMpCN10OgMJW2rZanw4vwIyH5px9eiXEKvVJtdxSQbhkGTuny+/RGICJ0AZpFjO/6F4",
    "__ssds": "2",
    "__ssuzjsr2": "a9be0cd8e",
    "__uzmaj2": "0a6c63ed-9a39-449c-aa93-577e74fda86a",
    "__uzmbj2": "1753971220",
    "__uzmlj2": "u53RduuRcE/t7/VIYGw6Hcl3FtmJEW6RfTRKu+cY858=",
    "utag_main__sn": "1",
    "utag_main_ses_id": "1753971222584%3Bexp-session",
    "__gads": "ID=9940ec38c64a7239:T=1753971222:RT=1753971222:S=ALNI_MZd7XHkk0R5tNdow1aI_Ze0LLgVow",
    "__gpi": "UID=000011734b0dbce0:T=1753971222:RT=1753971222:S=ALNI_MZaDu0E-l-FTqCzIcSrh_JYnb1Ddw",
    "__eoi": "ID=91b68745775da2d2:T=1753971222:RT=1753971222:S=AA-AfjbJi9_HRnPSUi3RXS_J9uqS",
    "_scid": "-bvR8p6g3mDf3b9xIKThxAzAnXILsg0h",
    "_gcl_au": "1.1.68273251.1753971224",
    "_ScCbts": "%5B%5D",
    "_fbp": "fb.1.1753971225891.219721597686947257",
    "utag_main__ss": "0%3Bexp-session",
    "_pin_unauth": "dWlkPU56a3paREJrWVdRdE56azNOUzAwTjJGa0xUZ3labUV0Tldaa01tWmpaRGhsWVRrNQ",
    "__gsas": "ID=5efe9c42859b5330:T=1753971260:RT=1753971260:S=ALNI_MasBWUOVn7dGRtEaRYGGClOW3gkEw",
    "__uzmcj2": "154641629192",
    "__uzmdj2": "1753971268",
    "__uzmfj2": "7f60004a95d886-d21d-450f-9a21-e38192683662175397122003648158-e86b9fa6b031609016",
    "s": "CgADuAEhojMvsMwZodHRwczovL3d3dy5lYmF5LmNvbS9zY2gvaS5odG1sP19ua3c9aVBob25lJl9zYWNhdD0wJl9mcm9tPVI0MCZfcGduPTIHAPgAIGiMy5E2MGQ0ZDU3MDE5ODBhYjFlYTk2MjA0MTFmZmZkNTY2OM82K7s*",
    "ebay": "%5Ejs%3D1%5Esbf%3D%23000000%5E",
    "__uzmc": "956533431558",
    "__uzmd": "1753971373",
    "__uzmf": "7f60004a95d886-d21d-450f-9a21-e381926836621753971217755155608-c5883f252e2c773534",
    "utag_main__se": "6%3Bexp-session",
    "utag_main__st": "1753973175269%3Bexp-session",
    "utag_main__pn": "6%3Bexp-session",
    "_scid_r": "9jvR8p6g3mDf3b9xIKThxAzAnXILsg0h65z-Bw",
    "_rdt_uuid": "1753971313524.fcabfab7-cb4b-48b0-b934-97600aad0f11",
    "cto_bundle": "lnBb3F9ITG5HM2dsWk5pNGE5YUxXNHVzYTR3c0hFR1c0UU1BMW1CUWVtUnN3TUpjTm5DSXBzSVJlUWVubyUyRkhNbW5waUljVjJFS1ElMkZiaWNud0RNZGluOXljJTJCRHI0JTJCcWJZS3YlMkIxSDJ0bGtOYTF6ZnBCJTJCc3JQSmtiTVI1cFFBUGVSS3ZCUFd3QjQxU1J1aVRPWlRVN0J1eXFSQkElM0QlM0Q",
    "_uetsid": "c64d66506e1811f0a512330497ddbec3|1d1kwdc|2|fy2|0|2038",
    "__deba": "JsK19ZP2oV1t25n2r6a3IrWB0iW9zWhOkpD89B4svXiTcgn2JE0MdYNcgaLOv1KVXR8UW1J2_XMwSXzXGqPFGF-5CvLAj23fy4zBKbULDd66orXFis72sZS-qm1k0Ll8UsrDtopnxH9OM3wV0F5uRg==",
    "_uetvid": "c64d91a06e1811f0bc5d5f498a94248f|vug1mu|1753971376557|3|1|bat.bing.com/p/insights/c/o",
    "ns1": "BAQAAAZhdx0gSAAaAANgAU2psrxNjNjl8NjAxXjE3NTM5NzEyMTc4MzdeXjFeM3wyfDV8NHw3fDEwfDQyfDQzfDExXl5eNF4zXjEyXjEyXjJeMV4xXjBeMV4wXjFeNjQ0MjQ1OTA3NftD8X1986acA6uKcBJQTeso6f9V",
    "nonsession": "BAQAAAZhdx0gSAAaAADMACGpsrxMxMDAtMDAwMQDKACBsTeKTNjBkNGQ1NzAxOTgwYWIxZWE5NjIwNDExZmZmZDU2NjgAywACaIuCmzMxEJ/N6das/YeyGzV3bKbBDoy+9L8*",
    "dp1": "bpbf/#0000002000000000000000006c4de2c0^bl/JPen-US6c4de293^"
}
url = "https://www.ebay.com/sch/i.html"
params = {
    "_nkw": "iPhone",
    "_sacat": "0",
    "_from": "R40",
    "_pgn": "2"
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)

html_str = response.content.decode()
root = etree.HTML(html_str)

data_list = root.xpath("//ul[@class='brwrvr__item-results brwrvr__item-results--list']/li")
for data in data_list:
    link = "".join(data.xpath(".//span[@class='bsig__title']/a/@href"))
    print(link)
